
module.exports = function (lab) {
    return {
        syncPublishedCouponSettingsByJSONRPC : function (session, jsonrpc = "jsonrpc") {
            if (!lab.slime_coupon){
                throw @lab.errors.not_support;
            }
            if (!session.currentOU) {
                throw @lab.errors.not_login;
            }
            return lab[jsonrpc].slime_test.doQuery({
                models : ["slime_coupons"],
                conditions : ["is_published = ?"],
                params : [true],
                start : 0, 
                limit : -1
            }).then(function ({list}) {
                @.async.all(list,function ({id}) {
                    lab[jsonrpc].slime_coupon.admin.getCouponDetail({coupon_id : id}).then(function (detail) {
                        
                        lab.slime_test.doSmartImport(session, "slime_coupons",@.merge.simple(detail.base_info,{
                            id : id
                        })).then(function () {
                            lab.slime_coupon.admin.saveCouponDetail(session,detail).pipe(this)
                        }).pipe(this)

                    }).pipe(this);
                }).pipe(this);
            })
        }
    }    
}